<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>유저 추가</title>
<%@ include file="/common/comm.jsp" %>
<script type="text/javascript">

function formCheck() {
	var password1 = $('input[name=password]').val();
	var password2 = $('input[name=password2]').val();
	
	if(password1 == password2) {
		return true;
	}else {
		return false;
	}
}

function init() {
	$('.submitButton').on('click' , function() {
		var url = '${initParam.base_path}/user.action?method=add';
		var id = $('input[name=id]').val();
		var password = $('input[name=password]').val();
		var name = $('input[name=name]').val();
		
		if(!formCheck()) {
			return false;
		}
		
		$.post(url, { 'id' : id, 'password' : password, 'name': name}, function(resp){
			var json = eval('(' + resp.responseText + ')');

			if(json.success)
			{
				alert("성공");
				
				//화면을 한번 갱신해 준다
				document.location.reload();
			}
			else
			{
				if(json.reason == "cant")
				{
					alert("실패");
					document.location.reload();
				}
			}
		});
		
		return false;
	});
}
</script>
</head>
<body>
	<div class="addUser">
		<form class="addUser" name="add" method="POST">
			<input type="text" name="id"> 아이디 <br>
			<input type="text" name="password"> 비밀번호 <br>
			<input type="text" name="password2"> 비밀번호 확인<br>
			<input type="text" name="name"> 이름 <br>
			<input class="submitButton" type="submit" />
		</form>
	</div>
</body>
</html>